package com.imstlife.vending.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.imstlife.vending.R;
import com.imstlife.vending.utils.GlideUtil;
import com.imstlife.vending.vo.DrinkInfo;

import java.util.List;

/**
 * Created by 开发分支11111修改内容了 on 16/10/27.
 */
public class DrinksAdapter extends BaseAdapter {

    private List<DrinkInfo> list;
    private LayoutInflater mInflater;
    private Context mContext;

    public DrinksAdapter(Context context, List<DrinkInfo> drinkList) {
        this.list = drinkList;
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
    }

    public void setItemList(List<DrinkInfo> drinkList) {
        this.list = drinkList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return list.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_drink, null);
            viewHolder.drinkIcon = (ImageView) convertView
                    .findViewById(R.id.img_item_drink_icon);
            viewHolder.priceBk = (ImageView) convertView
                    .findViewById(R.id.relayout_item_drink_price);
            viewHolder.price = (TextView) convertView
                    .findViewById(R.id.text_item_drink_price);
            viewHolder.imgOver = (ImageView) convertView.findViewById(R.id.img_item_drink_over);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        String url = list.get(position).getMinPicUrl();
        viewHolder.price.setText(list.get(position).getPrice() + "");
        GlideUtil.dontAnimLoad(mContext, url.trim(), viewHolder.drinkIcon);
        Log.d("feng",list.get(position).getCount()+"");
        if (list.get(position).getCount() == 0) {
            viewHolder.imgOver.setVisibility(View.VISIBLE);
            viewHolder.drinkIcon.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.imgOver.setVisibility(View.GONE);
            viewHolder.drinkIcon.setVisibility(View.VISIBLE);
        }

        viewHolder.priceBk.setBackgroundResource(R.mipmap.special_price);


        return convertView;
    }


    public class ViewHolder {
        public ImageView drinkIcon;
        public ImageView priceBk;
        private TextView price;
        public ImageView imgOver;

    }
}